﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using Rison.DataAccess.Data.ZJCP;
using System.Text;

namespace Rison.Web.ZJCP.ashx
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class load_departs : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write(String.Format("var _departs=[{0}]", findAllDeparts()));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        private string findAllDeparts()
        {
            string sql = "select t1.DepartId, t1.DepartName, t2.FieldTotal as onetotal, t2.FieldNum as onenum, t3.FieldTotal as twototal,t3.FieldNum as twonum, t1.url from Department t1, SelfExamination t2, NRBZ_Master t3 where t1.DepartID=t2.DepartID and t1.DepartId=t3.DepartId and t1.ifShow=1 order by t1.OrderName";
            DataSet ds = DbAccess.executeQuery(sql);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                if (i > 0)
                {
                    sb.Append(",");
                }
                sb.AppendFormat("{{departId:\"{0}\",departName:\"{1}\", onetotal:{2}, onenum:{3}, twototal:{4}, twonum:{5}, url:\"{6}\"}}", ds.Tables[0].Rows[i][0], ds.Tables[0].Rows[i][1], ds.Tables[0].Rows[i][2], ds.Tables[0].Rows[i][3], ds.Tables[0].Rows[i][4], ds.Tables[0].Rows[i][5], ds.Tables[0].Rows[i][6]);
            }
            return sb.ToString();
        }
    }
}
